package com.yj.timecapsule.common.utils;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Supplier;

/**
 * @author Sean
 * @CreateTime 2024-08-06  14:26
 * @Description
 * @Version 1.0
 */
public class AsyncTaskUtil {
    /**
     * 异步无返回值的任务
     * @param task 任务
     * @param executor 指定线程池
     * @return CompletableFuture对象
     * @param <T>
     */
    public static <T> CompletableFuture<Void> runAsync(Runnable task, Executor executor) {
        return CompletableFuture.runAsync(task, executor);
    }

    /**
     * 异步有返回值的任务
     * @param task 任务
     * @param executor 指定线程池
     * @return CompletableFuture对象
     * @param <T>
     */
    public static <T> CompletableFuture<T> supplyAsync(Supplier<T> task, Executor executor) {
        return CompletableFuture.supplyAsync(task,executor);
    }
}
